package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class TipoRetornoFProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static TipoRetornoFProduction instance = new TipoRetornoFProduction();

    public static TipoRetornoFProduction getInstance() {
        return instance;
    }


    /**
     * Regra: tipo_retorno_f : 'vazio' | tipo_variavel;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (basicParse(st, TokenClass.KEYWORD_VAZIO)) {
            return true;
        }
        if (TipoVariavelProduction.getInstance().analyze(st, et)) {
            return true;
        }
        return false;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.KEYWORD_VAZIO);

        //from TipoVariavelProduction
        first.add(TokenClass.IDENTIFIER);
        first.add(TokenClass.KEYWORD_INTEIRO);
        first.add(TokenClass.KEYWORD_REAL);
        first.add(TokenClass.KEYWORD_LOGICO);
        first.add(TokenClass.KEYWORD_CARACTERE);
        first.add(TokenClass.KEYWORD_STRING);
    }

    @Override
    protected void populateFollow() {
        follow.add(TokenClass.DELIMITER_OPENING_SQUARE_BRACKET);
        follow.add(TokenClass.IDENTIFIER);
    }
}
